<template>
  <div class="box">
    <!-- 头部 -->
    <div class="header">
      <van-icon name="arrow-left" @click="goBack" />
      <span>注册</span>
    </div>

    <div class="content">
      <van-cell-group :border="false">
        <van-field v-model="value" placeholder="请输入手机号" />
      </van-cell-group>
      <van-button
        round
        type="info"
        color="linear-gradient(to right, #ff60349d, #ee0a2596)"
        @click="next"
        >下一步</van-button
      >
    </div>
  </div>
</template>
  
  <script>
import axios from "axios";

export default {
  name: "index",
  data() {
    return {
      value: "",
    };
  },
  methods: {
    goBack() {
      this.$router.back();
    },
    next() {
      // 检查手机号是否被注册过
      let mi = /^1[3|5|7|8|9][0-9]\d{4,11}$/;
      if (!this.value) {
        alert("请填入内容");
        return;
      }
      if (mi.test(this.value) == false) {
        alert("请输入正确的格式");
        return;
      } else {
        /* let tel = localStorage.getItem("tel");
        if (tel === this.value) {
          alert("该手机号已经被注册，请重新登录");
        } */
        // console.log(tel);
        axios
          .post("/api/user/docheckphone", `tel=${this.value}`)
          .then((res) => {
            // 接口问题，数据不合适
            if (res.data.code == "200") {
              localStorage.setItem("tel", this.value);
              console.log(
                ' localStorage.setItem("tel",this.value)',
                localStorage.setItem("tel", this.value)
              );
              this.$router.push("/Reg/captcha");
            } 
            if (res.data.code == "10005") {
              alert("该手机号已经被注册，请重新登录")
              return;
            }
          });
      }
    },
  },
};
</script>
  
  <style scoped>
.header {
  height: 3.5rem;
  text-align: center;
  font-size: 1.3rem;
  line-height: 3.5rem;
  border-bottom: 2px solid gray;
}
.van-icon {
  float: left;
  padding-left: 10px;
  line-height: 3.5rem;
  color: rgb(24, 24, 64);
}
.content {
  margin: 3rem 1.5rem;
}
.van-button {
  margin: 1rem;
  width: 90%;
}
</style>